import { mockPluginStats, mockDownloadTrendData, mockPluginCategories } from '@/mock'
import { mockRequest } from '@/mock'

/**
 * 插件下载统计数据接口
 */
export interface PluginDownloadStats {
  totalDownloads: number
  growthRate: number
  timeLabels: string[]
  downloadData: number[]
  popularPlugins: Array<{
    name: string
    version: string
    downloads: number
    percentage: number
  }>
}

/**
 * 插件类别分布接口
 */
export interface PluginCategoryData {
  categoryName: string
  count: number
  percentage: number
}

/**
 * 插件统计数据
 */
export interface PluginStats {
  totalPlugins: number
  growthRate: number
  activeRate: number
  downloadStats: PluginDownloadStats
  categoryDistribution: PluginCategoryData[]
}

/**
 * 插件数据API服务
 */
export const pluginDataApi = {
  /**
   * 获取插件统计数据
   */
  getPluginStats: async (): Promise<PluginStats> => {
    return mockRequest(mockPluginStats)
  },
  
  /**
   * 获取插件下载趋势数据
   * @param period 时间周期
   */
  getDownloadTrend: async (period: 'week' | 'month' | 'all' = 'month'): Promise<{labels: string[], data: number[]}> => {
    const trendData = mockDownloadTrendData[period] || mockDownloadTrendData.month
    return mockRequest({
      labels: trendData.labels,
      data: trendData.downloads
    })
  },
  
  /**
   * 获取插件分类分布数据
   */
  getCategoryDistribution: async (): Promise<PluginCategoryData[]> => {
    // 转换mock数据格式以匹配接口
    const categories = mockPluginCategories.map(cat => ({
      categoryName: cat.name,
      count: cat.count,
      percentage: cat.percent
    }))
    return mockRequest(categories)
  }
} 